package cn.liutao.order.api;

import cn.hutool.core.util.StrUtil;
import cn.liutao.common.exception.BadRequestException;
import cn.liutao.common.utils.ServletUtils;
import cn.liutao.order.entity.vo.AlipayVo;
import cn.liutao.order.service.PayService;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: liutao
 * @description: 支付宝支付
 * @date: 2023/12/13 14:36
 */
@WebServlet("/order/alipay")
public class AliPayServlet extends HttpServlet {
    private PayService payService;

    @Override
    public void init(ServletConfig config) throws ServletException {
        payService = PayService.getInstance();
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String payNo = req.getParameter("payNo");
        if (StrUtil.isBlank(payNo)){
            throw new BadRequestException("请输入支付记录号");
        }
        AlipayVo alipayVo = payService.alipay(payNo);
        ServletUtils.ok(resp,alipayVo);
    }
}
